
# REQUIRES: Data/Roper Data.csv

# NOTE: Uses code from Stargazer Package Updates.R instead of the published version of Stargazer. See readme.txt.

################# Dependencies #################
# source("Load Packages.R")
# source("Analysis - Roper/Cleaning.R")

################# Table S2 - Predictors of US Public Support for Withdrawal, 1946-2021 #################
# With question features
roper$responseoptions_fac <- as.factor(roper$responseoptions)

OLS_q <- lm(percwithdraw ~  bEnemyVictory + bDeescalationOption + bOnesidedquestion + responseoptions_fac,
            data = roper)

# With situation features
OLS_s <- lm(percwithdraw ~  logcas + FPR + Vietnam + Gulf_War + Afghanistan + Iraq, 
            data = roper)

# With question and situation features
OLS_qs <- lm(percwithdraw ~  bEnemyVictory + bDeescalationOption + bOnesidedquestion + responseoptions_fac 
             + logcas + FPR + Vietnam + Gulf_War + Afghanistan + Iraq, 
             data = roper)

output <- stargazer(OLS_q, OLS_s, OLS_qs, title="Table A2: Replication of Observational Results with Dummy Variables for Number of Response Options",
                    align=TRUE, dep.var.labels=c(""), dep.var.caption="",
                    column.labels=c(" ","",""),
                    digits = 3, digits.extra = 0,
                    notes = "P-value shown in parentheses below coefficient", 
                    notes.append = FALSE,
                    report = "vc*p",
                    covariate.labels=c("Enemy Victory Framing", "Troop Reduction Option", "One-sided Question",
                                       "3 Response Options", "4 Response Options", "5 Response Options", "6 Response Options", "7 Response Options", "10 Response Options",
                                       "Log Cumulative Casualties", "Foreign Policy Restraint",
                                       "Vietnam", "Gulf War", "Afghanistan", "Iraq", "Constant"),
                    omit.stat=c("LL","ser","f","adj.rsq"), no.space=TRUE, notes.align="c", out = "Plots/Table S2 - Predictors of US Public Support for Withdrawal, 1946-2021_R.html")

webshot("Plots/Table S2 - Predictors of US Public Support for Withdrawal, 1946-2021_R.html", "Plots/Table S2 - Predictors of US Public Support for Withdrawal, 1946-2021_R.png", zoom=5, vwidth=580, vheight=600)
# Note: Add the independent variable groups in Word and remove "_R" from the file name
# webshot("Plots/Table S2 - Predictors of US Public Support for Withdrawal, 1946-2021.html", "Plots/Table S2 - Predictors of US Public Support for Withdrawal, 1946-2021.png", zoom=5, vwidth=475, vheight=580)

rm(OLS_q, OLS_qs, OLS_s, output)
